package com.example.demo.Controller;
import com.example.demo.Entity.User;
import com.example.demo.Server.userServer;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {

    @Autowired
    private userServer server;
    @Autowired
    Gson gson;
    /**
     * 登录验证
     * @param
     * @return
     */
    @ResponseBody
    @CrossOrigin
    @RequestMapping(value = "/isLogin",method = RequestMethod.POST,produces = "application/json;charset=UTF-8")
    public String isLogin(@RequestBody String account){
        //将接收到的数据转换为 User对象
        User user = gson.fromJson(account,User.class);
        if(server.isLogin(user) != null)
            return "success";
        else
            return "lose";
    }
    /**
     * 修改密码
     * @param
     * @return
     */

    @ResponseBody
    @CrossOrigin
    @RequestMapping(value = "/upPassword")
    public String upPassword(@RequestBody User user){
        System.out.println("修改密码");

        System.out.println("账号="+user.account+"密码="+user.password);
        return server.upPassword(user) == 1?"success":"loss";
    }


    @ResponseBody
    @CrossOrigin
    @RequestMapping(value = "/isLogin2")
    public String isLogin2(){

        return "success";

    }
}
